unit UMyDiagram;

interface
uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  ComCtrls, ExtCtrls, DBCtrls, Grids, DBGrids, StdCtrls, QBWindow,
  ImgList, ToolWin, Menus, QBFloatTable, QBParser, Db, QBPgWindow,
  ZConnection, ZAbstractRODataset, ZAbstractDataset, ZDataset,
  ZAbstractConnection;
type
  TMyPGQueryBuilder = class(TPgSQLQueryBuilder)
  public
    constructor Create(AOwner: TComponent); override;
  end;


function RectToStr(Rect: TRect): string;
function StrToRect(const Str: string; const Def: TRect): TRect;

implementation
const
  csLefts = ['[', '{', '('];
  csRights = [']', '}', ')'];

function RectToStr(Rect: TRect): string;
begin
  with Rect do
    Result := Format('[%d,%d,%d,%d]', [Left, Top, Right, Bottom]);
end;

function StrToRect(const Str: string; const Def: TRect): TRect;
var
  S: string;
  Temp: string[10];
  I: Integer;
begin
  Result := Def;
  S := Str;
  if (S[1] in csLefts) and (S[Length(S)] in csRights) then
  begin
    Delete(S, 1, 1); SetLength(S, Length(S) - 1);
  end;
  I := Pos(',', S);
  if I > 0 then
  begin
    Temp := Trim(Copy(S, 1, I - 1));
    Result.Left := StrToIntDef(Temp, Def.Left);
    Delete(S, 1, I);
    I := Pos(',', S);
    if I > 0 then
    begin
      Temp := Trim(Copy(S, 1, I - 1));
      Result.Top := StrToIntDef(Temp, Def.Top);
      Delete(S, 1, I);
      I := Pos(',', S);
      if I > 0 then
      begin
        Temp := Trim(Copy(S, 1, I - 1));
        Result.Right := StrToIntDef(Temp, Def.Right);
        Delete(S, 1, I);
        Temp := Trim(S);
        Result.Bottom := StrToIntDef(Temp, Def.Bottom);
      end;
    end;
  end;
end;

constructor TMyPGQueryBuilder.Create(AOwner: TComponent);
begin
  inherited;
  Left := 0;
  Top := 0;
  Width := 464;
  Height := 331;
  Align := alClient;
end;

end.

